package datadasetest;
import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.PreparedStatement;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class input1 extends JInternalFrame {
	Connection conn;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JTextField code;
	private JTextField ea;
	private JButton btnNewButton;
	private JLabel lblNewLabel_2;

	
	public input1(Connection c) {
		super("입력",true,true,false,false);
		
		setBounds(100, 100, 282, 199);
		getContentPane().setLayout(null);
		getContentPane().add(getLblNewLabel());
		getContentPane().add(getLblNewLabel_1());
		getContentPane().add(getCode());
		getContentPane().add(getEa());
		getContentPane().add(getBtnNewButton());
		getContentPane().add(getLblNewLabel_2());
		this.conn=c;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("code");
			lblNewLabel.setBounds(12, 25, 57, 15);
		}
		return lblNewLabel;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("ea");
			lblNewLabel_1.setBounds(12, 50, 57, 15);
		}
		return lblNewLabel_1;
	}
	private JTextField getCode() {
		if (code == null) {
			code = new JTextField();
			code.setBounds(81, 22, 116, 21);
			code.setColumns(10);
		}
		return code;
	}
	private JTextField getEa() {
		if (ea == null) {
			ea = new JTextField();
			ea.setColumns(10);
			ea.setBounds(81, 47, 116, 21);
		}
		return ea;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("저장");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
			try{
			String c=code.getText();
			int e= Integer.parseInt(ea.getText());
			
			String sql="insert into ptbl(serial, code, ea) values(ptbl_serial.nextval,?,?)";
			PreparedStatement pstmt = 
					conn.prepareStatement(sql);
			pstmt.setString(1,c);
			pstmt.setInt(2, e);
			pstmt.executeUpdate();//실행
			}catch(Exception ex){
				ex.printStackTrace();
			}
				
				
				}
			});
			btnNewButton.setBounds(81, 86, 116, 23);
		}
		return btnNewButton;
	}
	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("New label");
			lblNewLabel_2.setBounds(12, 145, 242, 15);
		}
		return lblNewLabel_2;
	}
}
